/*
 * Course
 * 
 * v1.1
 *
 * 01/24/2015
 * 
 * Copyright Richard R. Cachero Jr.
 */
package patchy;

import java.io.Serializable;
import java.util.ArrayList;

public class Course implements Serializable, Comparable{
    private String course;
    private String title;
    private String from;
    private String to;
    private String days;
    private int totalScore = 0;
    private int totalScoreMax = 1;
    private ArrayList<Event> events = new ArrayList<>();
    private double grade = 0.0;
    
    public Course(String course, String title, String from, String to, 
            String days) {
        this.course = course;
        this.title = title;
        this.from = from;
        this.to = to;
        this.days = days;
    }

    /**
     * @return the course
     */
    public String getCourse() {
        return course;
    }

    /**
     * @param course the course to set
     */
    public void setCourse(String course) {
        this.course = course;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the from
     */
    public String getFrom() {
        return from;
    }

    /**
     * @param from the from to set
     */
    public void setFrom(String from) {
        this.from = from;
    }

    /**
     * @return the to
     */
    public String getTo() {
        return to;
    }

    /**
     * @param to the to to set
     */
    public void setTo(String to) {
        this.to = to;
    }

    /**
     * @return the days
     */
    public String getDays() {
        return days;
    }

    /**
     * @param days the days to set
     */
    public void setDays(String days) {
        this.days = days;
    }

    /**
     * @return the scores
     */
    public int getTotalScore() {
        setTotalScore();
        return totalScore;
    }

    /**
     * @Calculates totalScore
     */
    public void setTotalScore() {
        int total = 0;
        for (int x = 0; x < getEvents().size(); x++) {
            total = total + getEvents().get(x).getScore();
        }
        totalScore = total;
    }

    /**
     * @return the scoresMax
     */
    public int getTotalScoreMax() {
        setTotalScoreMax();
        return totalScoreMax;
    }

    /**
     * @Calculates totalScoreMax
     */
    public void setTotalScoreMax() {
        int total = 1;
        for (int x = 0; x < getEvents().size(); x++) {
            total = total + getEvents().get(x).getScoreMax();
        }
        totalScoreMax = total;
    }
    
    /**
     * @return the events
     */
    public ArrayList<Event> getEvents() {
        return events;
    }

    /**
     * @param events the events to set
     */
    public void setEvents(ArrayList<Event> events) {
        this.events = events;
    }

    /**
     * @return the grade
     */
    public double getGrade() {
        setGrade();
        return grade;
    }

    /**
     * @param grade the grade to set
     */
    public void setGrade() {
        grade = ((double) getTotalScore() / getTotalScoreMax()) * 100.00;
    }
    
    /**
     * @param e an event to be associated with the course
     */
    public void addEvent(Event e) {
        this.events.add(e);
    }
    
    public String[] toCourseTableArray() {
        getGrade();
        Double grade = this.grade;
        String[] retVal = {course, title, from, days, grade.toString()};
        return retVal;
    }
    
    @Override
    public String toString() {
        return course + " _____ " + title + " _____ " + from + " _____ " +
                to + " _____ " + days + "_____" + Math.round(getGrade());
    }

    @Override
    public int compareTo(Object o) {
        return course.compareTo(((Course) o).getCourse());
    }

}
